// @author: caoshi
// @date: 2021-05-14 20:26
package test

import (
	"encoding/json"
	"fmt"
)

type User struct {
	Name string
	Age int
	Addr string
	Hobby string
}

func TestJSON()  {

	user := User{"张三", 19, "湖北武汉", "写代码"}
	b, _ := json.Marshal(user)
	fmt.Println(string(b))	// 对象转json字符串

	u1 := new(User)
	json.Unmarshal(b, u1)		// json 转对象
	fmt.Println(u1)

}

